{include file="public/header"/}
{load href="/public/static/Content/ThemesBusiness/FormPage.css"}

 <script src="/public/static/Scripts/ScriptsBusiness/VMFormData.js"></script>
 <!--引入引入kindeditor编辑器相关文件-->
    <link rel="stylesheet" href="/public/static/kindeditor-4.1.10/themes/default/default.css"/>
    <script charset="utf-8" src="/public/static/kindeditor-4.1.10/kindeditor-all.js"></script>
    <script charset="utf-8" src="/public/static/kindeditor-4.1.10/lang/zh_CN.js"></script>
<form id="formState" style="width:95%; text-align:center;">
    <table class="form_table" width="860px" style=" margin:0 auto;">
       
        <tr class="form_tr">
            <th style="padding-left:8px;width:80px;" class="form_td form_th_title">
                标题
            </th>
            <td style="width:90%;padding-left:8px;" colspan="4" class="form_td form_td_content">
                <input class="easyui-validatebox" type="text" id="card_title" name="card_title" style="width:600px;"
                       value="{$info.card_title}" data-options="required:true,tipPosition:'right'," />
            </td>
        </tr>
        <tr class="form_tr">
            <th style="padding-left:8px;width:80px;" class="form_td form_th_title">
                运行状态
            </th>
            <td style="width:90%;padding-left:8px;" colspan="4" class="form_td form_td_content">
                <select class="easyui-combobox"  name="type" id="type" data-options="required:true,tipPosition:'right'," style="width:152px;">
                  
                  <option value="1" >不影响之前</option>
                  
                  <option value="2" >同步更新全部</option>
                   
                </select>
            </td>
        </tr>

         <!--     <tr class="form_tr">
            <th style="padding-left:8px;width:80px;" class="form_td form_th_title">
                背景图片一
            </th>
            <td style="width:600px;padding-left:8px;" colspan="5" class="form_td form_td_content">
                <input class="easyui-validatebox" type="file"  style="width:600px;"
                      id="bg_img1"  data-options="tipPosition:'right'," />
            </td>
        </tr>

        <tr class="form_tr">
           
            <td style="width:600px;padding-left:8px;" colspan="6" class="form_td form_td_content">
                <img id="img1_view" src="/uploads/card/bg_img1/{$info.bg_img1}" style="width: 60px;height: 40px;">
            </td>
        </tr> -->

     <tr class="form_tr">
            <th style="padding-left:8px;width:80px;" class="form_td form_th_title">
                背景图片
            </th>
            <td style="width:600px;padding-left:8px;" colspan="5" class="form_td form_td_content">
                <input class="easyui-validatebox" type="file"  style="width:600px;"
                      id="bg_img2"  data-options="tipPosition:'right'," />
            </td>
        </tr>

          <tr class="form_tr">
           
            <td style="width:600px;padding-left:8px;" colspan="6" class="form_td form_td_content">
                <img id="img2_view" src="/uploads/card/bg_img2/{$info.bg_img2}" style="width: 60px;height: 40px;">
            </td>
        </tr>




        <tr class="form_tr">
          <!--   <th style="padding-left:8px;width:80px;" class="form_td form_th_title">
                保修卡介绍
            </th> -->
            <td colspan="5" style="width:100%;padding-left:8px; height:650px;border: none" class="form_td form_td_content">
                <textarea class="easyui-validatebox" name="card_desc" style="height:650px;width:100%;"
                          data-options="tipPosition:'right'" id="editor" >{$info.card_desc}</textarea>
            </td>
        </tr>

        <input type="hidden" id="img1" name="bg_img1" value="{$info.bg_img1}">
        <input type="hidden" id="img2" name="bg_img2" value="{$info.bg_img2}">
      
        <input type="hidden" name="pid" value="{$info.id}">
       
        <tr class="form_tr">
            <td class="form_button_panel" colspan="5" style="padding-right:8px">
                
                <a  id="save"  class="easyui-linkbutton form-toolbar-button" data-options="iconCls:'icon-save'">保存</a>
              
            </td>
        </tr>
    </table>
</form>

<script type="text/javascript">
 $(function () {
        //详情编辑器
        KindEditor.ready(function (K) {
            this.editor
                = K.create('textarea[id="editor"]', {
                items: ['source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
                    'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
                    'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
                    'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
                    'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
                    'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'multiimage',
                    'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
                    'anchor', 'link', 'unlink'],
                uploadJson: '/images',//指定上传图片的服务器端程序
                fileManagerJson: '/images',//指定浏览远程图片的服务器端程序
                allowFileManager: true
            });
        });
    });
</script>
<script>
   var formData = new FormData();
   $(function() {
       $("#save").on("click",function(){
                var content = editor.html();
                var card_title = $("#card_title").val();
                var type=$("input[name='type']").val();// 
                var pid=$("input[name='pid']").val();// 
                //var bg_img1=$("input[name='bg_img1']").val();// 
                var bg_img2=$("input[name='bg_img2']").val();// 

            
                var data = {"card_desc": content,card_title:card_title,type:type,pid:pid,bg_img2:bg_img2};
                $.ajax({
                       type: 'POST',
                       url: "{:url('admin/cardreport/report_save')}",
                     
                       data:data,
                       dataType: "json",
                       async: false,
                    error: function(request) {
                        alert("发送请求失败！");
                    },
                   success: function(data){
                        if (data.status == 1) {          
                            $.messager.alert('提示', data.msg, 'info');
                            //location.reload();
                              //closeDialog();
                        } else {
                            $.messager.alert('提示', data.msg, 'error');
                           // return;
                           // alert(data.msg);
                    
                        }
                       
                    } 
                });
       })
    })

     // document.getElementById("bg_img1").addEventListener("change", function (e) {
     //            const input = e.target;
     //            const files = e.target.files;
     //            if(files && files[0]) {
                   
     //                const file = files[0];
     //                if(file.size > 1024 * 1024 *3) {
     //                    input.value = '';
     //                    alert("图片太大");
     //                    return false;
     //                }else{
     //                    //111start
     //                    formData.append('photo', document.getElementById('bg_img1').files[0]);
     //                    $.ajax({
     //                            url: '/admin/uploadimg/uploadfoundation.html?path=card&type=bg_img1',
     //                            dataType: 'json',
     //                            type: 'POST',
     //                            async: false,
     //                            data:formData,
     //                            processData: false, // 使数据不做处理
     //                            contentType: false, // 不要设置Content-Type请求头
     //                            success: function (res) {
     //                                console.log(res.img);
     //                                if (res.status == 1) {
     //                                    $.messager.alert('提示', res.msg , 'ok');
     //                                    var imgurl=res.img;
     //                                    $("#img1").val(imgurl);
     //                                    $("#img1_view").attr("src",'/uploads/card/bg_img1/'+imgurl); 
     //                                } else {
     //                                    //$("#logo_img").val('');
     //                                    $.messager.alert('提示', res.msg , 'error');
     //                                }

     //                            },
     //                            error: function (response) {
     //                                //$("#logo_img").val('');
     //                                $.messager.alert('提示', '接口错误', 'error');
     //                            }
     //                    });

     //                    //111end
     //                }
     //            }
     //        });


     document.getElementById("bg_img2").addEventListener("change", function (e) {
                const input = e.target;
                const files = e.target.files;
                if(files && files[0]) {
                   
                    const file = files[0];
                    if(file.size > 1024 * 1024 *3) {
                        input.value = '';
                        alert("图片太大");
                        return false;
                    }else{
                        //111start
                        formData.append('photo', document.getElementById('bg_img2').files[0]);
                        $.ajax({
                                url: '/admin/uploadimg/uploadfoundation.html?path=card&type=bg_img2',
                                dataType: 'json',
                                type: 'POST',
                                async: false,
                                data:formData,
                                processData: false, // 使数据不做处理
                                contentType: false, // 不要设置Content-Type请求头
                                success: function (res) {
                                    console.log(res.img);
                                    if (res.status == 1) {
                                        $.messager.alert('提示', res.msg , 'ok');
                                        var imgurl=res.img;
                                        $("#img2").val(imgurl);
                                        $("#img2_view").attr("src",'/uploads/card/bg_img2/'+imgurl); 
                                    } else {
                                        //$("#logo_img").val('');
                                        $.messager.alert('提示', res.msg , 'error');
                                    }

                                },
                                error: function (response) {
                                    //$("#logo_img").val('');
                                    $.messager.alert('提示', '接口错误', 'error');
                                }
                        });

                        //111end
                    }
                }
            });

   
</script>

{include file="public/footer"/}